package com.rgst.utils;

import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;


/**
 * Created by tancw on 2019/12/15.
 */
public class DateUtil {

    public final static String DEFAULT_DAY_FORMAT = "yyyy-MM-dd";

    public final static String DEFAULT_DAYTIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static Date addDays(int days) {
        return org.apache.commons.lang3.time.DateUtils.addDays(now(), days);
    }

    public static Date addDays(Date date ,int days) {
        return org.apache.commons.lang3.time.DateUtils.addDays(date, days);
    }

    public static String format(Date date, String pattern) {
        return DateFormatUtils.format(date, pattern, Locale.CHINESE);

    }

    public static Date now() {
        return new Date();
    }

    public static Date parse(String dateStr) {
        try {
            return org.apache.commons.lang3.time.DateUtils.parseDate(dateStr, DEFAULT_DAY_FORMAT);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getBirthdayByIdNo(String idno) {
        if(StringUtils.isBlank(idno) || idno.length() != 18){
            return null;
        }
        return StringUtils.substring(idno,6,14);
    }

    public static void main(String[] args) {
       System.out.println(getBirthdayByIdNo("430423198811042515"));
    }
}
